package com.chara.rabbitmq_demo.com.chara.rabbitmq.work;

import com.chara.rabbitmq_demo.com.chara.rabbitmq.utils.ConnectionUtil;
import com.rabbitmq.client.*;

import java.io.IOException;

/**
 * @Classname Consumer1
 * @Description 消费者1
 * @Date 2025/10/8 21:35
 * @Author Chara
 */
public class Consumer1 {

    public static final String QUEUE_NAME = "work_queue";

    public static void main(String[] args) throws Exception {

        Connection connection = ConnectionUtil.getConnection();

        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, true, false, false, null);

        Consumer Consumer = new DefaultConsumer(channel){

            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1 body:"+body);
            }
        };
        channel.basicConsume(QUEUE_NAME, true, Consumer);

    }
}
